package com.zerui.manager.web;

import com.zerui.authority.annotation.Authorize;
import com.zerui.cola.dto.PageResponse;
import com.zerui.cola.dto.Response;
import com.zerui.manager.web.cmd.*;
import com.zerui.manager.web.vo.OpenPlanDeviceVO;
import com.zerui.manager.web.vo.OpenPlanVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @Author wh
 * @create_time 2023-08-23 15:33
 */
@Validated
@Api(value = "开门计划", tags = "门禁设备管理")
@RestController
@RequestMapping("/api/v1/open/plan")
@Authorize(value = {"access-control-manager:admin-plan"})
public class OpenPlanController {

    @Resource
    private OpenPlanService openPlanService;

	@ApiOperation(value = "添加", tags = "开门计划")
	@PostMapping
	public Response add(@RequestBody @Validated OpenPlanAddCmd openPlanAddCmd) {
		return openPlanService.add(openPlanAddCmd);
	}

	@ApiOperation(value = "修改", tags = "开门计划")
	@PutMapping
	public Response update(@RequestBody @Validated OpenPlanUpdateCmd openPlanUpdateCmd) {
		return openPlanService.update(openPlanUpdateCmd);
	}

	@ApiOperation(value = "删除", tags = "开门计划")
	@PostMapping("/delete/{id}")
	public Response deleteByIds(@PathVariable("id") @NotNull(message = "id不能为空") Long id) {
		return openPlanService.deleteById(id);
	}

	@ApiOperation(value = "启用禁用", tags = "开门计划")
	@PostMapping("/enable/{id}")
	public Response enableById(@PathVariable("id") @NotNull(message = "id不能为空") Long id) {
		return openPlanService.enableById(id);
	}

	@ApiOperation(value = "分页列表", tags = "开门计划")
	@PostMapping("/getPageList")
	public PageResponse<OpenPlanVO> getPageList(@RequestBody @Validated OpenPlanQryCmd openPlanQryCmd) {
		return openPlanService.getPageList(openPlanQryCmd);
	}

	@ApiOperation(value = "关联设备", tags = "开门计划")
	@PostMapping("/device/add")
	public Response add(@RequestBody @Validated OpenPlanDeviceAddCmd openPlanDeviceAddCmd) {
		return openPlanService.association(openPlanDeviceAddCmd);
	}

	@ApiOperation(value = "取消关联设备", tags = "开门计划")
	@PostMapping("/device/delete")
	public Response delete(@RequestBody @Validated OpenPlanDeviceAddCmd openPlanDeviceAddCmd) {
		return openPlanService.delete(openPlanDeviceAddCmd);
	}

	@ApiOperation(value = "设备分页列表", tags = "开门计划")
	@PostMapping("/getDevicePageList")
	public PageResponse<OpenPlanDeviceVO> getDevicePageList(@RequestBody @Validated OpenPlanDeviceQryCmd openPlanQryCmd) {
		return openPlanService.getDevicePageList(openPlanQryCmd);
	}


}
